import sqlite3

DB_path="requires.db"
con = sqlite3.connect(DB_path)
cur = con.cursor()

def reset_DB():
    cur.execute("DROP TABLE IF EXISTS required")
    cur.execute("CREATE TABLE required(package ,flags, name, ver,epoch,arch)")
    con.commit()
def insert_require(attributes:list):
    for attribute in attributes:
        if 'flags' not in attribute:
            attribute['flags']=None    
        if 'ver' not in attribute:
            attribute['ver']=None
        if 'epoch' not in attribute:
            attribute['epoch']=None
        if 'arch' not in attribute:
            attribute['arch']=None
    con.executemany(
        'INSERT INTO required VALUES(:package ,:flags, :name, :ver,:epoch,:arch)',
        attributes)
    con.commit();

def find_required(name):
    cur.execute("SELECT DISTINCT package FROM required WHERE name=?",(name,))
    return cur.fetchall()
       
def closeDB():
    cur.close();
    con.close();



